package com.hfut.manage.controller;



import com.hfut.manage.pojo.JobPosition;
import com.hfut.manage.pojo.Result;
import com.hfut.manage.service.IJobPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/job-position")
public class JobPositionController {

    @Autowired
    private IJobPositionService jobPositionService;

    @GetMapping
    public Result list() {
        return Result.success(jobPositionService.lambdaQuery().orderByAsc(JobPosition::getId).list());
    }

    @GetMapping("/{keyword}")
    public Result Select(@PathVariable("keyword") String name) {
        return Result.success(jobPositionService.lambdaQuery().like(JobPosition::getName,name).list());
    }

    @PostMapping
    public Result save(@RequestBody JobPosition jobPosition) {
        boolean success = jobPositionService.save(jobPosition);
        if (!success) {
            return Result.error(500, "新增部门失败");
        }
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Long id) {
        boolean success = jobPositionService.removeById(id);
        if (!success) {
            return Result.error(500, "删除部门失败");
        }
        return Result.success();
    }
}
